package com.yongjie.springbootlogin.config;

import com.yongjie.springbootlogin.interceptor.LoginHandlerIntercptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义配置类
 */
@Configuration

public class MySpringMvcConfig implements WebMvcConfigurer{

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("userLogin");
        //防止表单从新提交，创建一个代理路径
        registry.addViewController("/main.html").setViewName("index");

    }
    /*注册监听器*/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerIntercptor())
                //指定要拦截的请求 /** 表示拦截所有请求
                .addPathPatterns("/**")
                //排除不需要拦截请求路径
                .excludePathPatterns("/","/login","/userLogin","/registerpage","/usergister")
                //springboot2+之后需要将静态资源文件的访问路径也排除
                .excludePathPatterns("/css/*","/img/*","/js/*","/images/*","/bootstrap/*","/media/*");
    }
}
